/*
 *
 *  Copyright (C) 2010 Tal Eisenberg
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package base;

import tal.drivechain.matchers.VarMatcher;
import tal.drivechain.plugin.Channel;
import tal.drivechain.plugin.Module;
import tal.drivechain.variable.Variable;

/**
 *
 * @author Main
 */
public class Sequence extends Module {
    long[] durations;
    VarMatcher startTrigger, stopTrigger, bpmTrigger, sequenceTrigger;
    Variable varBpm;
    long bpm;
    boolean loop;
    
    @Override
    public void setupProperties() throws IllegalArgumentException {
        sequenceTrigger = (VarMatcher)props.getProperty("sequenceTrigger");
        startTrigger = (VarMatcher)props.getProperty("startTrigger");
        stopTrigger = (VarMatcher)props.getProperty("stopTrigger");
        bpmTrigger = (VarMatcher)props.getProperty("bpmTrigger");
        loop = (Boolean)((Variable)props.getProperty("loop")).getValue(this);
        varBpm = (Variable)props.getProperty("bpm");
        bpm = (Long)varBpm.getValue(this);
        Object[] durs = (Object[])props.getProperty("duration");
        durations = new long[durs.length];
        for (int i=0; i<durs.length; i++) 
            durations[i] = (Long)durs[i];
    }

    @Override
    protected void msgReceived(Variable in, long timestamp, Channel channel) {
        if (startTrigger.matches(in, channel, this)) {
            runSequence();
        } else if (stopTrigger.matches(in, channel, this)) {
            stopSequence();
        } else if (bpmTrigger.matches(in, channel, this)) {
            updateBPM();
        } else if (sequenceTrigger.matches(in, channel, this)) {
            updateSequence();
        }
    }

    private void runSequence() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    private void stopSequence() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    private void updateBPM() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    private void updateSequence() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

}
